//引入请求函数
import { http } from "@/utils/http";

//引入类型约束
import type { addCartResponse } from "@/types/cart";

/**
 * 购物车相关请求api
*/


//将商品加入购物车
export const reqAddCart = (skuId:string, count:number) => {
    return http<addCartResponse>({
        url:'/member/cart',
        method:"POST",
        data:{
            skuId,
            count
        }
    })
}

//获取购物车列表
export const reqCartList = () => {
    return http<addCartResponse[]>({
        url:"/member/cart",
        method:"GET"
    })
}

//删除、清空购物车单品
export const reqDeleteCartList = (skuIds:string[]) => {
    return http<addCartResponse>({
        url:"/member/cart",
        method:"DELETE",
        data:{ids:skuIds}
    })
}

//修改购物车单品
export const reqUpdateCart = (skuId:string, selected?:boolean, count?:number) => {
    return http({
        url:"/member/cart" +'/'+ skuId,
        method:"PUT",
        data:{
            selected,
            count
        }
    })
}

//购物车全选、取消全选
export const reqCartAllSelectedOrNoSelected = (selected:boolean) => {
    return http({
        url:"/member/cart/selected",
        method:"PUT",
        data:{selected}
    })
}